from django.db import models
from wxcloudrun.models import BaseModel


# 一番赏箱子
class YifanshangGame(BaseModel):
    state = models.IntegerField(default=0)  # 状态位 {0: 未上架, 1: 已上架}
    name = models.CharField(
        default="", max_length=100, unique=True, verbose_name="对局名称"
    )
    cover_url = models.CharField(max_length=255, verbose_name="封面url", default="")
    price = models.PositiveIntegerField(verbose_name="抽奖价格")
    pay_type = models.CharField(max_length=20, verbose_name="支付方式类似于[100,200]")
    game_num = models.PositiveIntegerField(default=20, verbose_name="游戏局数")
    raffle_counts = models.CharField(max_length=255, default="[]", verbose_name="抽奖玩法")
    sort = models.IntegerField(default=0, verbose_name="排序值")
    is_hide = models.IntegerField(default=0, verbose_name="是否隐藏")
    is_overlord = models.IntegerField(default=0, verbose_name="是否开启霸主模式")
    overlord_second = models.IntegerField(default=60, verbose_name="霸主模式持续时间")
    explain = models.UUIDField(null=True, verbose_name="说明uuid")

    class Meta:
        db_table = "YifanshangGame"
        indexes = [
            models.Index(fields=["uuid"]),
        ]


class YifanshangSonGame(BaseModel):
    state = models.IntegerField(default=0)  # 状态位 {0: 已售罄, 1: 销售中}
    game_uuid = models.UUIDField(verbose_name="对局GameUUid")
    price = models.IntegerField(verbose_name="单次抽奖价格")
    raffle_count = models.IntegerField(default=0, verbose_name="抽奖次数")
    remaining_raffle_count = models.IntegerField(default=0, verbose_name="剩余抽奖次数")
    box_num = models.IntegerField(default=1, verbose_name="箱子号码")

    class Meta:
        db_table = "YifanshangSonGame"
        indexes = [
            models.Index(fields=["uuid"]),
            models.Index(fields=["game_uuid"]),
            models.Index(fields=["deleted"]),
            models.Index(fields=["createdAt"]),
        ]


class YifanshangGameGood(BaseModel):
    game_uuid = models.UUIDField()
    good_uuid = models.UUIDField()
    good_level_uuid = models.UUIDField()
    good_type = models.IntegerField(default=0, verbose_name="商品类型, 最终赏/普通赏")
    good_desc_url = models.CharField(max_length=255)
    good_presale_type = models.CharField(
        max_length=16, default="现货", verbose_name="商品销售类型:现货/预售"
    )
    good_presale_time = models.DateTimeField(null=True, verbose_name="商品预售时间")
    count = models.IntegerField(default=1, verbose_name="总商品数量")
    current_count = models.IntegerField(default=0, verbose_name="商品剩余数量")

    class Meta:
        db_table = "YifanshangGameGood"  # table name
        indexes = [
            models.Index(fields=["uuid"]),
            models.Index(fields=["deleted"]),
            models.Index(fields=["createdAt"]),
            models.Index(fields=["game_uuid"]),
        ]
        ordering = ["good_uuid"]


class YifanshangRaffleRecord(BaseModel):
    user_uuid = models.UUIDField()
    game_uuid = models.UUIDField()
    good_uuid = models.UUIDField()
    raffle_count = models.IntegerField(default=1, verbose_name="抽奖发数")

    class Meta:
        db_table = "YifanshangRaffleRecord"  # table name
        indexes = [
            models.Index(fields=["uuid"]),
            models.Index(fields=["deleted"]),
            models.Index(fields=["createdAt"]),
            models.Index(fields=["user_uuid"]),
            models.Index(fields=["game_uuid"]),
        ]
        ordering = ["-createdAt"]
